<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <!-- 力度名称 -->
        <el-col :md="6" :lg="4">
          <p>力度名称</p>
          <el-input v-model="Api_GET_EventsManagementKyorugiSettingQO.NameFilter" size="mini" placeholder="请输入" clearable @change="freshData()" />
        </el-col>
        <!-- 按钮 -->
        <el-col :md="6" :lg="4">
          <el-button style="margin-top:27px" type="primary" size="mini" @click="freshData()">{{ $t('button.query') }}</el-button>
          <el-button style="margin-top:27px" type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-row :gutter="20" class="gl_my_15">
      <el-col :md="6" :lg="4">
        <el-button type="success" size="mini" @click="addCompetData()">添加力度</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="eventsTableData"
      style="width: 100%"
      stripe
      size="mini"
      align="center"
    >
      <el-table-column
        prop="name"
        label="名称"
        width="100"
        fixed="left"
        align="center"
      />
      <el-table-column
        prop="bodyThreshold"
        label="身体阈值"
        width="70"
        align="center"
      />
      <el-table-column
        prop="headThreshold"
        label="头部阈值"
        width="70"
        align="center"
      />
      <el-table-column
        prop="maxFoul"
        label="最大犯规"
        width="70"
        align="center"
      />
      <el-table-column
        prop="gConsideration"
        label="青方审议"
        width="70"
        align="center"
      />
      <el-table-column
        prop="rConsideration"
        label="红方审议"
        width="70"
        align="center"
      />
      <el-table-column
        prop="rounds"
        label="回合数"
        width="60"
        align="center"
      />
      <el-table-column
        prop="roundMinutes"
        label="回合时间（分）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="roundSeconds"
        label="回合时间（秒）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="breakMinutes"
        label="休息时间（分）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="breakSeconds"
        label="休息时间（秒）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="timingMinutes"
        label="计时时间（分）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="timingSeconds"
        label="计时时间（秒）"
        width="110"
        align="center"
      />
      <el-table-column
        prop="extraMinutes"
        label="加时赛时间（分）"
        width="120"
        align="center"
      />
      <el-table-column
        prop="extraSeconds"
        label="加时赛时间（秒）"
        width="120"
        align="center"
      />
      <el-table-column
        prop="extraScore"
        label="加时赛分数"
        width="90"
        align="center"
      />
      <el-table-column
        prop="creationTime"
        label="创建时间"
        width="140"
        align="center"
      >
        <template slot-scope="{row}">
          <span v-if="row.creationTime">
            {{ row.creationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="creatorName"
        label="创建人"
        width="90"
        align="center"
      />
      <el-table-column
        prop="operating"
        label="操作"
        width="100"
        fixed="right"
        align="center"
      >
        <template slot-scope="{row,$index}">
          <el-button type="text" size="mini" @click="editCompetData(row,$index)">{{ $t('table.edit') }}</el-button>
          <el-button type="text" size="mini" @click="delect(row,$index)">
            <span class="gl_color_error">{{ $t('table.delete') }}</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row class="gl_pt_20" style="text-align: center;">
      <el-pagination
        :current-page="Api_GET_EventsManagementKyorugiSettingQO.Page"
        :page-size="Api_GET_EventsManagementKyorugiSettingQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
    <!-- 子组件添加编辑 -->
    <test-form ref="testForm" @pushTabelData="getTabelDate" @editTabelData="updataTabelDate" />
  </div>
</template>

<script>
import testForm from './editData';
import { Api_GET_EventsManagementKyorugiSettingQO } from '@/lib/form/game/swaggerForm';
import { api_POST_EventsManagementKyorugiSetting, api_GET_EventsManagementKyorugiSetting, api_DELETE_EventsManagementKyorugiSettingId, api_PUT_EventsManagementKyorugiSettingId } from '@/extend/api/gameswaggerApi/app.js';

export default {
  name: 'Account',
  components: {
    testForm
  },
  data() {
    return {
      Api_GET_EventsManagementKyorugiSettingQO: new Api_GET_EventsManagementKyorugiSettingQO(),
      // queryChapterName: '',
      eventsTableData: [], // 表格中的数据
      // showTableData: [],
      totalPage: 0,
      loading: false
    };
  },
  created () {
    // 获取数据
    this.freshData();
  },
  methods: {
    // 获取数据
    freshData(page) {
      this.loading = true;
      this.Api_GET_EventsManagementKyorugiSettingQO.Page = page || 1;
      this.Api_GET_EventsManagementKyorugiSettingQO.SkipCount = (this.Api_GET_EventsManagementKyorugiSettingQO.Page - 1) * this.Api_GET_EventsManagementKyorugiSettingQO.MaxResultCount;
      api_GET_EventsManagementKyorugiSetting(this.Api_GET_EventsManagementKyorugiSettingQO).then(res => {
        this.loading = false;
        this.eventsTableData = res.items;
        this.totalPage = res.totalCount;
      }).catch(res => {
        this.loading = false;
      });
    },
    // 添加数据
    addCompetData() {
      this.$refs.testForm.open();
    },
    // 修改数据
    editCompetData(row, index) {
      this.$refs.testForm.open(row);
    },
    // 添加
    getTabelDate(data) {
      api_POST_EventsManagementKyorugiSetting(data).then(res => {
        this.freshData();
        this.$message({
          message: '添加成功',
          type: 'success'
        });
      }, error => {
        console.log(error.error.message);
        if (error.error.message.indexOf('已经存在') === -1) {
          this.$message({
            message: '该名称已存在',
            type: 'warning'
          });
        }
      });
      this.$refs.testForm.close();
    },
    // 修改数据
    updataTabelDate(data) {
      api_PUT_EventsManagementKyorugiSettingId(data.id, data).then(res => {
        this.freshData();
      });
      this.$refs.testForm.close();
    },
    // 删除
    delect(row, index) {
      this.$confirm('你确定要删除这条信息?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api_DELETE_EventsManagementKyorugiSettingId(row.id).then(res => {
          this.freshData();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
        });
      });
    },
    // 重置
    reset() {
      this.Api_GET_EventsManagementKyorugiSettingQO = new Api_GET_EventsManagementKyorugiSettingQO();
      this.freshData();
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_EventsManagementKyorugiSettingQO.MaxResultCount = MaxResultCount;
      this.freshData();
    },
    pageIndexChange(currentPage) {
      this.freshData(currentPage);
    }
  }
};
</script>
